<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/style.css" />
		<link href="../css/calendar/calendar.css" rel="stylesheet"/>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav ding-bar">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">保养日历</h1>
		</header>
		<div class="mui-content">
	        <div style="background: #fff;border-radius: 0.2rem;width: ;padding-bottom: 0.2rem;width: 95%;margin:0.3rem auto 0px;box-shadow: 1px 1px 3px #cbcdd2,-1px -1px 3px #cbcdd2;">
	    		<div id="date" ></div>
	    		<div class="biaoji">
	    			<div class="yby"><span></span>已保养</div>
	    			<div class="dby"><span></span>待保养</div>
	    			<div class="yq"><span></span>逾期</div>
	    			<div class="dqrq"><span></span>当前日期</div>
	    		</div>
	    	</div>
		    <div class="byrl-container">
		    	<h1 class="byrl-t"><span id="riqi">7月30日</span>&nbsp;&nbsp;</h1>
		    	<ul class="byrl-t-ul">
		    		<!--<li>
		    			<div><span class="byrl-dian" ></span><p>电梯编号：</p><div>ASDFG123455</div></div>
		    			<div><span></span><p>电梯地址：</p><div>七里河区西湖雅筑小区(西津东路南)梁家庄-13号楼</div></div>
		    		     <button class="byqd">保养签到</button>
		    		</li>
		    		<li >
		    			<div><span class="byrl-dian" ></span ><p>电梯编号：</p><div>ASDFG123455</div></div>
		    			<div><span></span><p>电梯地址：</p><div>七里河区西湖雅筑小区(西津东路南)梁家庄-13号楼</div></div>
		    		     <button class="byqd">保养签到</button>
		    		</li>-->
		    	</ul>
		    </div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/jquery-1.8.0.min.js" ></script>
		<script type="text/javascript" src="../js/head_public.js" ></script>
		<script type="text/javascript" src="../js/common.js" ></script>
		<script type="text/javascript" src="../js/session.js" ></script>
		<script type="text/javascript" src="../css/calendar/calendar1.js" charset="utf-8"></script>
		<script type="text/javascript">
			mui.init()
			var nowdate = new Date();
		    var year = nowdate.getFullYear();
		    var month = nowdate.getMonth()+1;
		    var day = nowdate.getDate();
		    var nowtime = year+"-"+month+"-"+day;
		    var yuangongid="";
			function writeDay(n) //据条件写日期的下拉框
		   {
			   var e = document.reg_testdate.DD; optionsClear(e);
			   for (var i=1; i<(n+1); i++)
			        e.options.add(new Option( i +'日', i));
		   }
		   function IsPinYear(year)//判断是否闰平年
		   {     return(0 == year%4 && (year%100 !=0 || year%400 == 0));}
		   function optionsClear(e)
		   {
		        e.options.length = 1;
		   }
			$('.item-buydate').mdater({maxDate: new Date,minDate: new Date(1900, 0, 1)});
		</script>
		<script>
			$(function(){
			   getdata()
			   var nowDate=new Date();
			   var $year=nowDate.getFullYear();
			   var $month=nowDate.getMonth()+1;
			   var $day=nowDate.getDate();
			   var $date=year+"-"+month+"-"+day;
			   getBaoyanglist($date,$year,$month,$day)
			})
			function getdata(){
//				判断登录
                 var work_id=getCookie("workid");
                 var work=getCookie("work");
                 var userid=getCookie("userid");
                 if(userid==""||userid==null){
                 	alert("您还没有登录，请先登录")
                 	location.href="../public/login.html";
                 }else{
                 	if(work!="2"){
						alert("您不是管理员,您没有权限")
						mui.openWindow({url:"../public/index.html"})
					}
                 	var param={};
                 	param.work_id=work_id;
                 	param.member_id=userid;
                 	param.member_work=work;                
                 	$.post(net+"/public/index.php?s=api/elevator",param,function(res){
                 		if(res.code=="200"){
                 			if(res.result!=null&&res.result.length!=0){
                 				var yeartag=$(".yeartag").html();
                 				var monthtag=$(".monthtag").html();
                 				var monstr=monthtag.substring(0,monthtag.length-1);
                 				$.each(res.result,function(){
                 					var $mouth="";
                 					if(this.mouth.indexOf("0")==0){
	                 					$mouth=this.mouth.substring(1,this.mouth.length);
	                 				}else{
	                 					$mouth=this.mouth;
	                 				}
                 					var $day="";
                 					if(this.day.indexOf("0")==0){
	                 					$day=this.day.substring(1,this.day.length);
	                 				}else{
	                 					$day=this.day;
	                 				}
                 					var status=this.status;
	                 				if(yeartag==this.year&&monstr==$mouth){
	                 					$('.md_datearea li').not('.prevdate,.nextdate').each(function(){
	                 						var day=$(this).html();
	                 						if(day==$day){
	                 							if(status==1){	
	                 								$(this).css("background","#ffcccc")
	                 							}else if(status==2){
	                 								$(this).css("background","#cccccc")
	                 							}else if(status==-1){
	                 								$(this).css("background","#ffea95")
	                 							}
	                 						}
	                 					})
	                 				}
                 				})
	                 		}
                 		}
                 		
                 	})
                 }
			}
			//获取当前保养信息
			function getBaoyanglist(choose_date,$year,$month,$day){
				$(".byrl-t-ul").empty()
				$("#riqi").html($year+"年"+$month+"月"+$day+"日")
				//判断登录
                 var work_id=getCookie("workid");
                 var work=getCookie("work");
                 var userid=getCookie("userid");
                 if(userid==""||userid==null){
                 	alert("您还没有登录，请先登录")
                 	location.href="../public/login.html";
                 }else{
                 	var param={};
                 	param.work_id=work_id;
                 	param.member_id=userid;
                 	param.member_work=work; 
                 	param.service_time=choose_date;
                 	$.post(net+"/public/index.php?s=api/elevator/ElevatorServer",param,function(res){
                 		if(res.code=="200"){
                 			if(res.result!=null&&res.result.length!=0){
                 				var str="";
                 				$.each(res.result,function(index,val){
                 					var btn="";
                 					if(this.status=="1"){
                 						btn='<button class="byqd" data-id="'+this.id+'">保养签到</button>'
                 					}else if(this.status=="2"){
                 						btn='<button data-id="'+this.id+'">已完成</button>'
                 					}else if(this.status=="-1"){
                 						btn='<button class="byqd" data-id="'+this.id+'">保养签到</button><button style="background:rgb(255, 234, 149);margin-right:15px">逾期</button>'
                 					}
                 					str+='<li><div><span class="byrl-dian" ></span><p>电梯编号：</p><div>'+this.elevator_code+'</div></div><div><span></span><p>电梯地址：</p><div>'+this.address+'</div></div>'+btn+'</li>'
                 				})
                 				$(".byrl-t-ul").html(str)
                 			}
                 		}
                 		
                 	})
                 }
			}
			mui(".byrl-t-ul").on("tap",".byqd",function(){
				var data_id=$(this).attr("data-id")
				mui.openWindow({"url":"saomaweibao.html?id="+data_id})
			})
//			mui(".byrl-t-ul").on("tap",".finish[data-id]",function(){
//				var data_id=$(this).attr("data-id")
//				mui.openWindow({"url":"weibaofinish.html"+data_id})
//			})
		</script>
	</body>

</html>